INDF    EQU     0
TMR0    EQU     1
OPT     EQU     81H
STATUS  EQU     3
FSR     EQU     4
INTCON  EQU     0BH
PIR1    EQU     0CH
PIE1    EQU     8CH
PIR2    EQU     0DH
PIE2    EQU     8DH
TMR1L   EQU     0EH
TMR1H   EQU     0FH
T1CON   EQU     10H
TMR2    EQU     11H
T2CON   EQU     12H
PR2     EQU     92H
CCPR1L  EQU     15H
CCPR1H  EQU     16H
CCP1CON EQU     17H
ADRES   EQU     1EH
ADCON0  EQU     1FH
ADCON1  EQU     9FH
RA      EQU     5
RB      EQU     6
RC      EQU     7
TRISA   EQU     85H
TRISB   EQU     86H
TRISC   EQU     87H
C       EQU     0
DC      EQU     1
Z       EQU     2
RP0     EQU     5
TOIE    EQU     5
TOIF    EQU     2
TMR2ON  EQU     2
ADIE    EQU     6
PEIE    EQU     6
GIE     EQU     7
ADON    EQU     0
ADIF    EQU     1
GODOEN  EQU     2
ADCS0   EQU     6
ADCS1   EQU     7
POR     EQU     1
BOR     EQU     0
ALO     EQU     20H
AHO     EQU     21H
BLO     EQU     22H
BHO     EQU     23H
CLO     EQU     24H
CHO     EQU     25H
DLO     EQU     26H
DHO     EQU     27H
TEMP    EQU     28H
SIGN    EQU     29H
COUNT   EQU     20H
DIGITS  EQU     21H
ADDR    EQU     22H
SLAVE   EQU     23H
TXBUF   EQU     24H
RXBUF   EQU     25H
DAT     EQU     26H
SIK     EQU     24H
SIG     EQU     25H
CON3    EQU     2AH
CON4    EQU     2BH
CON5    EQU     2CH
CON6    EQU     2DH
DAT0    EQU     2EH
DAT1    EQU     2FH
CONT    EQU     30H
TIME1   EQU     31H
TIME2   EQU     32H
STEP    EQU     33H
CONE    EQU     34H        
CONF    EQU     35H        
TIM     EQU     36H        
KML     EQU     37H
FLAG    EQU     38H        
CON1    EQU     39H
CON2    EQU     3AH
DAM1    EQU     3BH        
DAM2    EQU     3CH
DAS0    EQU     3DH
DAS1    EQU     3EH
CON     EQU     2DH
IN      EQU     0        
TN      EQU     1
GLF     EQU     1
ZJ      EQU     2
STR     EQU     3
OVER    EQU     4
HT      EQU     5
TD      EQU     6
CUT     EQU     7
AUTO    EQU     5        
START   EQU     0
STOP    EQU     1
WZ      EQU     4
CUTI    EQU     2
J1      EQU     5        
J2      EQU     7
ALM     EQU     6
TMR2ON  EQU     2
TMR2IE  EQU     1
TMR2IF  EQU     1
TTM     EQU     0A0H        
TDM     EQU     0A1H
TIME11  EQU     0A2H        
STEP11  EQU     0A4H        
FLAG1   EQU     0B2H
PTM     EQU     0B3H
FSTM    EQU     0B4H
SWF     EQU     0
DEX     EQU     7
TF      EQU     6
SDA     EQU     3
SCL     EQU     4
GL2     EQU     0FFH
GLTM    EQU     0FEH
        ORG     0
        GOTO    MAN
        ORG     4
        GOTO    INF
MAN     CALL    CLRM
        CALL    PORTA
        CALL    J
        CALL    WM
        CALL    WT
        CALL    STAT
        BCF     RA,3
        MOVLW   GL2
        MOVWF   FSR
        MOVLW   0FFH
        MOVWF   INDF
        MOVLW   83H
        MOVWF   TMR0
        BSF     INTCON,TOIE
        BSF     T2CON,TMR2ON
        BSF     INTCON,PEIE
        BSF     STATUS,RP0
        BSF     PIE1,TMR2IE
        BCF     STATUS,RP0
        BSF     INTCON,GIE
MAX     NOP
        GOTO    MAX
INF     CLRWDT
        BTFSS   INTCON,TOIF
        GOTO    INFY
        MOVLW   84H
        MOVWF   TMR0
        CALL    PORTA
        INCF    SIGN,1
        MOVLW   0AH
        SUBWF   SIGN,0
        SKPC
        GOTO    INFX
        CLRF    SIGN
        CALL    SAZ
        CALL    ST
        CALL    FS
        CALL    DAOUT
        CALL    AD
        CALL    RTT
        CALL    J
        INCF    TIM,1
        MOVLW   64H
        SUBWF   TIM,0
        SKPC
        GOTO    INFX
        CLRF    TIM
        CALL    CL
        CALL    IT
INFX    CALL    DIS
        BCF     INTCON,TOIF
        RETFIE
INFY    CALL    PWM
        BCF     PIR1,TMR2IF
        RETFIE
SAZ     BTFSS   RA,WZ
        GOTO    Z1
        BTFSC   FLAG,ZJ
        GOTO    Z2
        CLRF    DAM1
        CLRF    DAM2
        BSF     FLAG,ZJ
        BCF     FLAG,TN
        BCF     FLAG,STR
        MOVLW   0EFH
        MOVWF   TIME1
        MOVWF   TIME2
        MOVWF   STEP
        CLRF    SIK
        CLRF    SIG
        GOTO    Z4
Z2      BTFSC   FLAG,STR
        CALL    SE
        MOVF    TIM,1 
        SKPZ
        GOTO    ZX
        CALL    SE1
        BTFSS   FLAG,STR
Z4      CALL    ONN
        GOTO    ZX
Z1      BTFSS   FLAG,ZJ
        GOTO    ZX
        BCF     FLAG,ZJ
        BTFSS   FLAG,STR
        GOTO    Z3
        BCF     FLAG,STR
        CALL    WEPM
Z3      CALL    PORT
ZX      RETURN
PORT    MOVLW   20H
        MOVWF   FSR
PORT1   CLRF    INDF
        INCF    FSR,1
        BTFSS   FSR,6
        GOTO    PORT1
STAT    MOVLW   0AAH        
        MOVWF   TIME1
        MOVWF   TIME2
        MOVWF   STEP
        RETURN
DAOUT   CALL    CKML
        SKPNZ
        GOTO    DT1
        BTFSC   FLAG,TD
        GOTO    DTY
        BTFSC   FLAG,ZJ
        GOTO    DTY
        BTFSC   FLAG,STR
        GOTO    DT2
DT1     CLRF    DAM1
        CLRF    DAM2
        GOTO    DTY
DT2     MOVF    DAS1,0     
        IORWF   DAS0,0
        SKPNZ
        GOTO    DTY
        MOVLW   1
        ADDWF   DAT0,1
        SKPNC
        ADDWF   DAT1,1
        MOVF    DAS0,0
        SUBWF   DAT0,0
        SKPZ
        GOTO    DTY
        MOVF    DAS1,0
        SUBWF   DAT1,0
        SKPZ
        GOTO    DTY
        CLRF    DAT1
        CLRF    DAT0
        BCF     FLAG,IN
        CALL    FCUT
        MOVF    DAM1,0
        SUBWF   CON1,0
        SKPC
        DECF    CON2,1
        MOVF    DAM2,0
        SUBWF   CON2,0
        BTFSC   FLAG,CUT
        GOTO    DT4
        SKPNC
        CALL    DAD
        GOTO    DTY
DT4     CALL    DAS
DTY     RETURN
PWM     MOVLW   7
        MOVWF   T2CON
        BSF     STATUS,RP0
        MOVLW   0FFH
        MOVWF   PR2
        BCF     STATUS,RP0
        MOVLW   0CH
        MOVWF   CCP1CON
        MOVF    DAM2,0
        MOVWF   CCPR1L
        BCF     CCP1CON,4
        BTFSC   DAM1,0
        BSF     CCP1CON,4
        BCF     CCP1CON,5
        BTFSC   DAM1,1
        BSF     CCP1CON,5
        BCF     PIR1,TMR2IF
        RETURN
KEYT    EQU     20H
KEYS    EQU     21H
SH      EQU     22H
SD      EQU     23H
SE      BTFSC   FLAG,STR
        GOTO    SEA
        CLRF    SH
SEA1    CLRF    DAM1
        CLRF    DAM2
        GOTO    SEX
SEA     MOVF    SIK,0
        MOVWF   SIG
        MOVF    RA,0
        ANDLW   10H
        MOVWF   SIK
        BTFSS   RA,CUTI
        GOTO    SEA2
        CALL    SEA1
        GOTO    SEA3
SEA2    BCF     STATUS,C
        RLF     SIG,0
        ADDWF   SIK,0
        SUBLW   20H
        SKPNZ
        CALL    SE4
SEA3    MOVF    RC,0
        ANDLW   3
        MOVWF   CONE
        SUBLW   3
        SKPZ
        GOTO    SEB
        BCF     FLAG,HT
        CLRF    KEYT
        CLRF    KEYS
        GOTO    SEX
SEB     MOVF    CONE,0
        SUBWF   SH,0
        SKPNZ
        GOTO    SEC
        BCF     FLAG,HT
        MOVF    CONE,0
        MOVWF   SH
        GOTO    SED
SEC     BTFSC   FLAG,HT
        GOTO    SEE1
SED     INCF    KEYT,1
        BTFSS   KEYT,5
        GOTO    SEX
        CLRF    KEYT
        INCF    KEYS,1
        MOVLW   9
        SUBWF   KEYS,0
        SKPZ
        GOTO    SEE
        CLRF    KEYS
        BSF     FLAG,HT
SEE1    INCF    SD,1
        MOVLW   5
        SUBWF   SD,0
        SKPC
        GOTO    SEX
        CLRF    SD
SEE     BTFSC   RA,CUTI
        GOTO    SEF
        BTFSS   RC,START
        CALL    DAD
        BTFSS   RC,STOP
        CALL    DAS
        GOTO    SEX
SEF     BTFSS   RC,START
        CALL    INS
        BTFSS   RC,STOP
        CALL    DES
        GOTO    SEX
SE1     BTFSC   RA,AUTO
        GOTO    SEX
        BTFSS   RA,CUTI
        GOTO    SE9
        BCF     RA,3
        BCF     RC,J1
        GOTO    SE10
SE9     BSF     RC,J1
        BSF     RA,3
SE10    BTFSC   FLAG,STR
        GOTO    SEG
        BSF     FLAG,STR
        BSF     FLAG,TN
SE3     MOVLW   1
        MOVWF   STEP
        GOTO    SE4
SEG     BTFSS   RA,CUTI
        GOTO    SE5
        MOVLW   1
        SUBWF   STEP,0
        SKPZ
        GOTO    SEH5
        MOVLW   FLAG1
        MOVWF   FSR
        BTFSS   INDF,TF
        GOTO    SEH1
        BCF     INDF,TF
        GOTO    SEH
SEH1    MOVLW   99H
        SUBWF   TIME2,0
        SKPZ
        GOTO    SEH5
        MOVLW   0FH
        ANDWF   TIME1,0
        SKPZ
        GOTO    SEH5
        BSF     INDF,TF
        MOVLW   50H
        SUBWF   TIME1,0
        SKPZ
        GOTO    SEH3
        CALL    CLTM
        GOTO    SEH
SEH3    MOVLW   40H
        SUBWF   TIME1,0
        SKPZ
        GOTO    SEH4
        CALL    CLCU
        GOTO    SEH
SEH4    MOVLW   0B8H
        MOVWF   FSR
        SWAPF   TIME1,1
        CLRC
        RLF     TIME1,0
        ADDWF   FSR,1
        MOVF    INDF,0
        MOVWF   TIME1
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   TIME2
        GOTO    SEX
SEH     CLRF    STEP
        GOTO    SE6
SEH5    BSF     FLAG,IN
        MOVF    TIME1,0
        MOVWF   CON1
        MOVF    TIME2,0
        MOVWF   CON2
        CALL    FTM
        GOTO    SE6
SE5     BSF     FLAG,IN
        MOVF    DAM1,0
        MOVWF   CON1
        MOVF    DAM2,0
        MOVWF   CON2
        CALL    FCUT
        INCF    FSR,1
        MOVF    INDF,0
        ANDLW   3
        INCF    FSR,1
        IORWF   INDF,0
        SKPZ
        GOTO    SE6
        MOVF    CON2,0
        MOVWF   INDF
        DECF    FSR,1
        MOVF    CON1,0
        MOVWF   INDF
SE6     CALL    INCSTP
        MOVLW   32H
        SUBWF   STEP,0
        SKPNZ
        GOTO    SE3
SE4     BCF     FLAG,IN
        BTFSC   RA,CUTI
        GOTO    SE8
        CALL    FCUT
        MOVF    CON1,0
        MOVWF   DAM1
        MOVF    CON2,0
        MOVWF   DAM2
SE8     CALL    FTM
        MOVF    CON1,0
        MOVWF   TIME1
        MOVF    CON2,0
        MOVWF   TIME2
SEX     RETURN
AD      BTFSC   FLAG,ZJ
        GOTO    ADX
        BTFSC   FLAG,TD
        GOTO    AD7
        MOVLW   1
        SUBWF   STEP,0
        SKPNZ
        GOTO    ADX
ADG     BTFSS   FLAG,STR
        GOTO    ADX
        CALL    CKML
        SKPNZ
        GOTO    ADX
        INCF    CONE,0
        SUBWF   KML,0
        SKPNZ
        GOTO    ADX
ADS     CALL    ADY     
        MOVLW   TDM
        MOVWF   FSR
        MOVLW   2
        SUBWF   ADRES,0
        SKPC
        GOTO    AD3
        CLRF    INDF
        BCF     FLAG,TD
        GOTO    ADX
AD3     INCF    INDF,1
        MOVLW   6
        SUBWF   INDF,0
        SKPC
        GOTO    ADX
        BSF     FLAG,TD
        BCF     FLAG,GLF
        BSF     STATUS,RP0
        CLRF    TTM
        BCF     STATUS,RP0
        MOVLW   TIME11
        MOVWF   FSR
        MOVF    TIME1,0
        MOVWF   INDF
        INCF    FSR,1
        MOVF    TIME2,0
        MOVWF   INDF
        INCF    FSR,1
        MOVF    STEP,0
        MOVWF   INDF
        INCF    FSR,1
        MOVF    DAM1,0
        MOVWF   INDF
        INCF    FSR,1
        MOVF    DAM2,0
        MOVWF   INDF
        INCF    FSR,1
        MOVF    FLAG,0   
        MOVWF   INDF
        INCF    FSR,1
        MOVF    DAS0,0
        MOVWF   INDF
        INCF    FSR,1
        MOVF    DAS1,0
        MOVWF   INDF
        INCF    FSR,1
        MOVF    DAT0,0
        MOVWF   INDF
        INCF    FSR,1
        MOVF    DAT1,0
        MOVWF   INDF
AD5     CLRF    DAM1
        CLRF    DAM2
        MOVLW   0CAH   
        MOVWF   TIME1
        MOVWF   TIME2
        BCF     FLAG,STR
        GOTO    ADX
AD7     BTFSC   FLAG,STR
        GOTO    AD81
        BTFSC   RA,AUTO
        GOTO    AD5
        CALL    ST8
        MOVLW   TTM
        MOVWF   FSR
        MOVLW   10H
        MOVWF   INDF
        GOTO    AD111
AD81    MOVLW   20H
        SUBWF   TIME1,0
        SKPNZ
        GOTO    AD112
AD111   CALL    DT2
        GOTO    ADX
AD112   MOVLW   TIME11
        MOVWF   FSR
        MOVF    INDF,0
        MOVWF   TIME1
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   TIME2
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   STEP
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   DAM1
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   DAM2
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   FLAG
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   DAS0
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   DAS1
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   DAT0
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   DAT1
        BCF     FLAG,TD
        MOVLW   TTM
        MOVWF   FSR
        CLRF    INDF
ADX     RETURN
IT      BTFSC   FLAG,ZJ
        GOTO    ITX
        BTFSS   FLAG,STR
        GOTO    ITX
        CALL    INS
        BTFSC   FLAG,TD
        GOTO    ITX
        BCF     FLAG,IN
        CALL    FTM
        MOVF    TIME1,0
        SUBWF   CON1,0
        SKPZ
        GOTO    ITX
        MOVF    TIME2,0
        SUBWF   CON2,0
        SKPZ
        GOTO    ITX
        CLRF    TIME1
        CLRF    TIME2
        CALL    FCUT
        MOVF    CON1,0
        MOVWF   DAM1
        MOVF    CON2,0
        MOVWF   DAM2
        CALL    INCSTP
        CLRF    DAT0
        CLRF    DAT1
        CALL    CKML
        SKPZ
        GOTO    IT3
        CLRF    DAM2
        CLRF    DAM1
        GOTO    ITX
IT3     DECF    CONE,0
        SUBWF   KML,0
        SKPZ
        GOTO    IT4
        CALL    STAT
        BSF     FLAG,OVER
        BCF     FLAG,STR
        MOVLW   FLAG1
        MOVWF   FSR
        BTFSS   INDF,DEX
        GOTO    IT6
        BCF     INDF,DEX
        CALL    WEPM
IT6     CALL    DD1     ;--
        GOTO    ITX
IT4     BCF     FLAG,OVER
        INCF    CONE,0
        SUBWF   KML,0
        SKPZ
        GOTO    IT5
        CALL    ADY
        MOVLW   20H
        ADDWF   ADRES,0
        SKPNC
        MOVLW   0FFH
        BSF     STATUS,RP0
        MOVWF   GL2
        BCF     STATUS,RP0
        CLRF    CONE
        CLRF    CONF
        CALL    DACNT6
        MOVF    DAS1,0
        IORWF   DAS0,0
        SKPZ
        GOTO    ITX
        INCF    DAS0,1
        GOTO    ITX
IT5     CALL    DACNT
ITX     RETURN
ST      BTFSC   FLAG,TD
        GOTO    ST3
        BTFSC   FLAG,ZJ
        GOTO    ST3
        BTFSC   FLAG,STR
        GOTO    ST3
        BTFSC   RA,AUTO
        GOTO    ST3
        CALL    CLD
        MOVF    KML,1
        SKPNZ
        GOTO    ST3     ;--
        MOVLW   0BBH
        CALL    SU
        SKPZ
        GOTO    ST4
        MOVLW   0BDH
        CALL    SU
        SKPNZ
        GOTO    ST1
ST2     MOVLW   0BDH
        MOVWF   FSR
        MOVF    INDF,0
        MOVWF   CONE
        MOVLW   0BFH
        MOVWF   FSR
        MOVF    CONE,0
        SUBWF   INDF,0
        SKPC
        GOTO    ST1
        MOVLW   0DDH
ST5     MOVWF   STEP
        MOVWF   TIME1
        MOVWF   TIME2
        GOTO    ST3
ST4     MOVLW   0EEH
        GOTO    ST5     ;--
ST1     MOVLW   1
        MOVWF   STEP
ST8     CLRF    DAM1
        CLRF    DAM2
        CLRF    TIME1
        CLRF    TIME2
        BSF     FLAG,STR
        BCF     FLAG,GLF
        CLRF    DAT0
        CLRF    DAT1
        CALL    DACNT
ST3     RETURN
DACNT   BTFSS   FLAG,TD
        GOTO    DACNTF
        MOVLW   0A5H
        MOVWF   FSR
        MOVF    INDF,0
        MOVWF   CON1
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   CON2
        GOTO    DACNTG
DACNTF  BCF     FLAG,IN
        CALL    FCUT
DACNTG  CALL    RR
        MOVF    CON1,0
        MOVWF   CONE
        MOVF    CON2,0
        MOVWF   CONF
DACNT6  BTFSS   FLAG,TD
        GOTO    DACNTB
        CLRF    CON1
        CLRF    CON2
        GOTO    DACNTC
DACNTB  MOVF    DAM1,0
        MOVWF   CON1
        MOVF    DAM2,0
        MOVWF   CON2
DACNTC  CALL    RR
        MOVF    CONF,0
        MOVWF   CON
        MOVF    CON1,0
        SUBWF   CONE,0
        MOVWF   CON3
        SKPNC
        GOTO    DACNTA
        MOVLW   1
        SUBWF   CON,1
        SKPC
        GOTO    DACNT1
DACNTA  MOVF    CON2,0
        SUBWF   CON,0
        MOVWF   CON4
        SKPC
        GOTO    DACNT1
        MOVF    CON3,0
        IORWF   CON4,0
        SKPZ
        GOTO    DACNT2
DACNT5  CLRF    DAS0
        CLRF    DAS1
        GOTO    DACNT4
DACNT2  BCF     FLAG,CUT
        GOTO    DACNT3
DACNT1  MOVF    CONE,0
        SUBWF   CON1,0
        MOVWF   CON3
        SKPC
        DECF    CON2,1
        MOVF    CONF,0
        SUBWF   CON2,0
        MOVWF   CON4
        BSF     FLAG,CUT
DACNT3  MOVF    CON3,0
        MOVWF   BLO
        MOVF    CON4,0
        MOVWF   BHO
        MOVLW   0AH
        MOVWF   ALO
        CLRF    AHO
        CALL    DIV
        MOVF    BLO,0
        MOVWF   CON3
        MOVF    BHO,0
        MOVWF   CON4
        IORWF   CON3,0
        SKPNZ
        GOTO    DACNT5
        BTFSS   FLAG,TD
        GOTO    DACNT7
        MOVLW   20H
        MOVWF   CON1
        CLRF    CON2
        GOTO    DACNT8
DACNT7  BCF     FLAG,IN
        CALL    FTM
DACNT8  MOVF    CON2,0
        MOVWF   CONE
        CALL    BTD
        MOVF    CONE,0
        MOVWF   ALO
        CLRF    AHO
        MOVLW   58H
        MOVWF   BLO
        MOVLW   2
        MOVWF   BHO
        CALL    MULT
        MOVF    CLO,0
        MOVWF   CON5
        MOVF    CHO,0
        MOVWF   CON6
        MOVF    CON1,0
        MOVWF   CONE
        CALL    BTD
        MOVF    CONE,0
        MOVWF   ALO
        CLRF    AHO
        MOVLW   0AH
        MOVWF   BLO
        CLRF    BHO
        CALL    MULT
        MOVF    CON5,0
        ADDWF   CLO,0
        MOVWF   BLO
        BTFSC   STATUS,C
        INCF    CHO,1
        MOVF    CON6,0
        ADDWF   CHO,0
        MOVWF   BHO
        MOVF    CON3,0
        MOVWF   ALO
        MOVF    CON4,0
        MOVWF   AHO
        CALL    DIV
        MOVF    BLO,0
        MOVWF   DAS0
        MOVF    BHO,0
        MOVWF   DAS1
DACNT4  RETURN
RR      MOVLW   6
        MOVWF   TEMP
        BCF     STATUS,C
RR1     RRF     CON2,1
        RRF     CON1,1
        DECFSZ  TEMP,1
        GOTO    RR1
        BTFSC   CON2,3
        BSF     CON1,0
        BTFSC   CON2,4
        BSF     CON1,1
        MOVLW   3
        ANDWF   CON2,1
        RETURN
INCSTP  INCF    STEP,1
        MOVF    STEP,0
        MOVWF   CONE
        CALL    ADD1
        MOVF    CONE,0
        MOVWF   STEP
        RETURN
ONN     BTFSC   FLAG,TN
        GOTO    ONN1
        MOVLW   99H
        SUBWF   TIME1,0
        SKPNZ
        GOTO    ONN2
        MOVLW   11H
        ADDWF   TIME1,1
        ADDWF   TIME2,1
        ADDWF   STEP,1
        GOTO    ONN3
ONN2    CLRF    STEP
        BSF     FLAG,TN
ONN1    CALL    INCSTP        
        MOVLW   32H
        SUBWF   STEP,0
        SKPZ
        GOTO    ONN4
        BCF     FLAG,TN
        CLRF    TIME1
        CLRF    TIME2
        CLRF    STEP
        GOTO    ONN3
ONN4    BCF     FLAG,IN
        CALL    FTM
        MOVF    CON1,0
        MOVWF   TIME1
        MOVF    CON2,0
        MOVWF   TIME2
ONN3    RETURN
DAD     BTFSS   FLAG,TD
        GOTO    DADA
        MOVLW   0A6H
        MOVWF   FSR
        MOVF    INDF,0
        SUBWF   DAM2,0
        SKPNC
        GOTO    DAD2
DADA    MOVLW   3
        SUBWF   DAM1,0
        SKPZ
        GOTO    DAD1
        MOVLW   0FFH
        SUBWF   DAM2,0
        SKPNZ
        GOTO    DAD2
DAD1    INCF    DAM1,1
        BTFSS   DAM1,2
        GOTO    DAD2
        CLRF    DAM1
        INCF    DAM2,1
DAD2    RETURN
DAS     MOVF    DAM1,0
        IORWF   DAM2,0
        SKPNZ
        GOTO    DASX
        DECF    DAM1,1
        MOVLW   0FFH
        SUBWF   DAM1,0
        SKPZ
        GOTO    DASX
        MOVLW   3
        MOVWF   DAM1
        DECF    DAM2,1
DASX    RETURN
FCUT    MOVLW   0C0H
        GOTO    FCT
FTM     MOVLW   40H
FCT     MOVWF   FSR
        MOVF    STEP,0
        MOVWF   CONE
        CALL    BTD
        DECF    CONE,1
        BCF     STATUS,C
        RLF     CONE,0
        ADDWF   FSR,1
        BTFSS   FLAG,IN
        GOTO    FCT1
        MOVF    CON1,0
        MOVWF   INDF
        INCF    FSR,1
        MOVF    CON2,0
        MOVWF   INDF
        GOTO    FCT2
FCT1    MOVF    INDF,0
        MOVWF   CON1
        INCF    FSR,1
        MOVF    INDF,0
        MOVWF   CON2
FCT2    RETURN
BTD     MOVF    CONE,0
        ANDLW   0F0H
        SKPNZ
        GOTO    BTD1
        MOVWF   CONF
        SWAPF   CONF,1
        MOVLW   0FH
        ANDWF   CONE,1
BTD2    MOVLW   0AH
        ADDWF   CONE,1
        DECFSZ  CONF,1
        GOTO    BTD2
BTD1    RETURN
CLD     MOVLW   3FH
        MOVWF   FSR
        MOVLW   0FFH
        MOVWF   KML
CLD1    INCF    KML,1
        MOVF    KML,0
        SUBLW   1DH
        MOVLW   2FH
        SKPC
        GOTO    CLD4
        INCF    FSR,1
        MOVF    INDF,0
        INCF    FSR,1
        IORWF   INDF,0
        SKPZ
        GOTO    CLD1
        MOVLW   4
        SUBWF   KML,0
        SKPNC
        GOTO    CLD3
CLD2    MOVF    KML,0
CLD4    MOVWF   STEP
        INCF    STEP,1
        CLRF    TIME1
        CLRF    TIME2
        CLRF    KML
CLD3    RETURN
DES     DECF    TIME1,1
        MOVF    TIME1,0
        SUBLW   0FFH
        SKPNZ
        GOTO    DES1
        MOVF    TIME1,0
        MOVWF   CONE
        CALL    DEC1
        MOVF    CONE,0
        MOVWF   TIME1
        GOTO    DES2
DES1    MOVLW   59H
        MOVWF   TIME1
        DECF    TIME2,1
        MOVF    TIME2,0
        SUBLW   0FFH
        SKPNZ
        GOTO    DES3
        MOVF    TIME2,0
        MOVWF   CONE
        CALL    DEC1
        MOVF    CONE,0
        MOVWF   TIME2
        GOTO    DES2
DES3    MOVLW   99H
        MOVWF   TIME2
DES2    RETURN
DEC1    MOVF    CONE,0
        ANDLW   0FH
        SUBLW   0FH
        SKPZ
        GOTO    EC2
        MOVF    CONE,0
        ANDLW   0F0H
        ADDLW   9
        MOVWF   CONE
EC2     RETURN
INS     INCF    TIME1,1 
        MOVF    TIME1,0
        SUBLW   5AH
        SKPNZ
        GOTO    INS1
        MOVF    TIME1,0
        MOVWF   CONE
        CALL    ADD1
        MOVF    CONE,0
        MOVWF   TIME1
        GOTO    INS2
INS1    CLRF    TIME1
        INCF    TIME2,1
        MOVF    TIME2,0
        SUBLW   9AH
        SKPNZ
        GOTO    INS3
        MOVF    TIME2,0
        MOVWF   CONE
        CALL    ADD1
        MOVF    CONE,0
        MOVWF   TIME2
        GOTO    INS2
INS3    CLRF    TIME2
INS2    RETURN
ADD1    MOVF    CONE,0
        ANDLW   0FH
        SUBLW   0AH
        SKPZ
        GOTO    DDR
        MOVLW   0F0H
        ANDWF   CONE,0
        ADDLW   10H
        MOVWF   CONE
DDR     RETURN
CLRM    MOVLW   20H
        MOVWF   FSR
CLRM1   CLRF    INDF
        INCF    FSR,1
        BTFSS   FSR,7
        GOTO    CLRM1
        MOVLW   0A0H
        MOVWF   FSR
CLRM2   CLRF    INDF
        INCF    FSR,1
        MOVF    FSR,1
        SKPZ
        GOTO    CLRM2
        RETURN
CLTM    MOVLW   40H
        GOTO    CL11
CLCU    MOVLW   0C0H
CL11    MOVWF   FSR
        MOVLW   40H
        MOVWF   20H
CL22    CLRF    INDF
        INCF    FSR,1
        DECFSZ  20H,1
        GOTO    CL22
        RETURN
DIS     INCF    CONT,1
        MOVLW   6
        SUBWF   CONT,0
        SKPNC
        CLRF    CONT
        BCF     STATUS,C
        RRF     CONT,0
        ADDLW   31H
        MOVWF   FSR
        MOVF    CONT,0
        MOVWF   CONE
        SWAPF   CONE,1
        RLF     CONE,1
        MOVF    INDF,0
        MOVWF   CONF
        BTFSC   CONT,0
        SWAPF   CONF,0
        ANDLW   0FH
        IORWF   CONE,1
        MOVLW   0FFH
        MOVWF   RB
        MOVF    CONE,0
        MOVWF   RB
        MOVLW   32H
        SUBWF   TIM,0
        BCF     RB,4
        SKPC
        BSF     RB,4
        RETURN
CKML    MOVF    STEP,0
        MOVWF   CONE
        CALL    BTD
        MOVF    CONE,0        
        SUBWF   KML,0
        RETURN
WM      MOVLW   5
        MOVWF   CON
WM1     MOVLW   3FH
        MOVWF   FSR
        MOVLW   87H
        MOVWF   INDF
        MOVLW   0FH
        MOVWF   CONF
        CALL    WR
        DECFSZ  CON,1
        GOTO    WM1
        RETURN
WEPM    MOVLW   0C1H
        MOVWF   FSR
        MOVLW   0E0H
        SUBWF   INDF,0
        SKPC
        GOTO    WEPM1
        CALL    REM
        GOTO    EPM6
WEPM1   CALL    LDA     ;--
        MOVLW   3EH
        MOVWF   FSR
                MOVLW   0FH
        MOVWF   CONF
        MOVLW   87H
        MOVWF   CON
        MOVWF   3FH
EPM3    INCF    FSR,1
        MOVLW   80H
        SUBWF   FSR,0
        MOVLW   0BAH
        SKPNZ
        MOVWF   FSR
        CLRWDT
        CALL    WR
        INCF    CONF,1
        DECFSZ  CON,1
        GOTO    EPM3
        CALL    REM
        MOVF    3FH,1
        SKPNZ
        GOTO    WEPM1
EPM6    RETURN
WR      CALL    BSTART
        MOVLW   0A0H
        MOVWF   TXBUF
        CALL    TX
        MOVF    CONF,0
        MOVWF   TXBUF
        CALL    TX
        MOVF    INDF,0
        MOVWF   TXBUF
        CALL    TX
        CALL    BSTOP
        MOVLW   0F0H
        MOVWF   DAT
WR1     CALL    U5S
        CLRWDT
        CALL    U5S
        DECFSZ  DAT,1
        GOTO    WR1
        RETURN
TX      MOVLW   8
        MOVWF   COUNT
TX0     MOVLW   3
        BSF     STATUS,RP0
        MOVWF   TRISC
        BCF     STATUS,RP0
        RLF     TXBUF,1        
        BTFSS   STATUS,C
        GOTO    TX1
        BSF     RC,SDA
        GOTO    TX2
TX1     BCF     RC,SDA
TX2     CALL    U5S
        CALL    U5S
        CALL    U5S
        BSF     RC,SCL
        CALL    U5S
        CALL    U5S
        CALL    U5S
        CALL    U5S
        BCF     RC,SCL
        DECFSZ  COUNT,1
        GOTO    TX0
        BSF     STATUS,RP0
        MOVLW   0BH
        MOVWF   TRISC
        BCF     TRISC,4
        BSF     TRISC,3
        BCF     STATUS,RP0
        CALL    U5S
        CALL    U5S
        CALL    U5S
        BSF     RC,SCL
        CALL    U5S
        CALL    U5S
        CALL    U5S
TX3     BTFSC   RC,SDA
        CALL    U5S
        BCF     RC,SCL
        RETURN
RX      MOVLW   8  
        MOVWF   COUNT
        CLRF    RXBUF
RX1     BSF     STATUS,RP0
        MOVLW   0BH
        MOVWF   TRISC
        BCF     STATUS,RP0
        BSF     RC,SCL
        CALL    U5S
        BSF     STATUS,C
        BTFSS   RC,SDA
        BCF     STATUS,C
        RLF     RXBUF,1
        CALL    U5S
        BCF     RC,SCL
        CALL    U5S
        CALL    U5S
        DECFSZ  COUNT,1
        GOTO    RX1
        CALL    BITOUT
        RETURN
BITOUT  BSF     STATUS,RP0
        MOVLW   3
        MOVWF   TRISC
        BCF     STATUS,RP0
        BCF     RC,SDA
        CALL    U5S
        BSF     RC,SCL
        CALL    U5S
        CALL    U5S
        BCF     RC,SCL
        RETURN
BSTART  BSF     STATUS,RP0
        MOVLW   3
        MOVWF   TRISC
        BCF     STATUS,RP0
        BSF     RC,SCL
        BSF     RC,SDA
        CALL    U5S
        CALL    U5S
        BCF     RC,SDA
        CALL    U5S
        BCF     RC,SCL
        RETURN
U5S     NOP
        NOP
        NOP
        NOP
        NOP
        RETURN
BSTOP   BSF     STATUS,RP0
        MOVLW   3
        MOVWF   TRISC
        BCF     STATUS,RP0
        BSF     RC,SCL
        BCF     RC,SDA
        CALL    U5S
        CALL    U5S
        BSF     RC,SDA
        CALL    U5S
        RETURN
HADD    MOVF    ALO,0
        ADDWF   BLO,1
        SKPNC
        INCF    BHO,1
        MOVF    AHO,0
        ADDWF   BHO,1
        RETURN
SETUP   MOVLW   10H
        MOVWF   TEMP
        MOVF    BHO,0
        MOVWF   DHO
        MOVF    BLO,0
        MOVWF   DLO
        CLRF    BHO
        CLRF    BLO
        RETURN
MULT    CALL    SETUP
MLOOP   RRF     DHO,1
        RRF     DLO,1
        SKPNC
        CALL    HADD
        RRF     BHO,1
        RRF     BLO,1
        RRF     CHO,1
        RRF     CLO,1
        DECFSZ  TEMP,1
        GOTO    MLOOP
        RETURN
DIV     CALL SETUP      
        CLRF    CHO
        CLRF    CLO
DLOOP   BCF     STATUS,C
        RLF     DLO,1
        RLF     DHO,1
        RLF     CLO,1
        RLF     CHO,1
        MOVF    AHO,0
        SUBWF   CHO,0
        SKPZ
        GOTO    NOCHK
        MOVF    ALO,0
        SUBWF   CLO,0
NOCHK   SKPC
        GOTO    NOGO
        MOVF    ALO,0
        SUBWF   CLO,1
        SKPC
        DECF    CHO,1
        MOVF    AHO,0
        SUBWF   CHO,1
        BSF     STATUS,C
NOGO    RLF     BLO,1
        RLF     BHO,1
        DECFSZ  TEMP,1
        GOTO    DLOOP
        RETURN
ADY     BSF     STATUS,RP0
        MOVLW   4
        MOVWF   ADCON1
        BCF     STATUS,RP0
        MOVLW   0C1H
        MOVWF   ADCON0
        CALL    U5S
        BSF     ADCON0,2
AY      CALL    U5S
        BTFSC   ADCON0,2
        GOTO    AY
        BCF     ADCON0,2
        BCF     ADCON0,0
        BSF     STATUS,RP0
        MOVLW   7
        MOVWF   ADCON1
        BCF     STATUS,RP0
        RETURN
PORTA   BSF     STATUS,RP0        
        MOVLW   0F7H
        MOVWF   TRISA   
        MOVLW   0
        MOVWF   TRISB
        MOVLW   13H
        MOVWF   TRISC
        MOVLW   2
        MOVWF   OPT
        MOVLW   7
        MOVWF   ADCON1
        BCF     STATUS,RP0
        RETURN
REM     MOVLW   87H
        MOVWF   CON
        MOVLW   0A0H
        MOVWF   TXBUF
        CALL    BSTART
        CALL    TX
        MOVLW   0FH
        MOVWF   TXBUF
        CALL    TX
        MOVLW   0A1H
        MOVWF   TXBUF
        CALL    BSTART
        CALL    TX
        MOVLW   3EH
        MOVWF   FSR
REM1    INCF    FSR,1
        CLRWDT
        MOVLW   80H
        SUBWF   FSR,0
        MOVLW   0BAH
        SKPNZ
        MOVWF   FSR
        CALL    RX
        MOVF    RXBUF,0
        MOVWF   INDF
        DECFSZ  CON,1
        GOTO    REM1
        CALL    BSTOP
        RETURN
GL      CALL    CKML
        SKPNZ
        GOTO    GLX
        MOVLW   FLAG1
        MOVWF   FSR
        BTFSC   INDF,DEX
        GOTO    GLX
        BTFSC   FLAG,ZJ
        GOTO    GLX
        BTFSS   FLAG,STR
        GOTO    GLX
        MOVLW   GL2
        MOVWF   FSR
        CALL    ADY
        MOVF    ADRES,0
        SUBWF   INDF,0
        MOVLW   GLTM
        MOVWF   FSR
        SKPC
        GOTO    GLD
        CLRF    INDF
        GOTO    GLX
GLD     INCF    INDF,1
        MOVLW   0AH
        SUBWF   INDF,0
        SKPC
        GOTO    GLX
        CLRF    INDF
        MOVLW   0BCH
        MOVWF   TIME2
        MOVWF   TIME1
        CLRF    DAM1
        CLRF    DAM2
        BCF     FLAG,STR
        BSF     FLAG,GLF
        BCF     FLAG,TD
        MOVLW   TTM
        MOVWF   FSR
        CLRF    INDF
GLX     RETURN
W       CLRF    CONF
        MOVLW   40H
        MOVWF   FSR
        CLRF    INDF
W1      CALL    WR
        INCF    CONF,1
        MOVLW   0FFH
        SUBWF   CONF,0
        SKPZ
        GOTO    W1
        RETURN
WT      MOVLW   PTM
        MOVWF   FSR
        MOVLW   6
        MOVWF   INDF
WT4     CALL    REM
        MOVLW   0C1H
        MOVWF   FSR
        MOVF    INDF,0
        ANDWF   41H,0
        SUBLW   0FFH
        SKPZ
        GOTO    WT1
        MOVLW   PTM
        MOVWF   FSR
        DECFSZ  INDF,1
        GOTO    WT4
        CALL    W
        CALL    CLRM
        CALL    WM
        GOTO    WTX
WT1     MOVF    3FH,1
        SKPZ
        GOTO    WTA
        CALL    REM
        GOTO    WT1
WTA     MOVLW   0C1H
        MOVWF   FSR
        MOVF    INDF,0
        MOVWF   20H
        INCF    FSR,1
        INCF    FSR,1
        MOVF    INDF,0
        ANDWF   20H,0
        SUBLW   0FFH
        SKPZ
        GOTO    WTX
        CLRF    INDF
        MOVLW   0C0H
        MOVWF   CONF
        MOVLW   40H
        MOVWF   CON
WT2     CALL    WR
        INCF    CONF,1
        DECFSZ  CON,1
        GOTO    WT2
        MOVLW   0C0H
        MOVWF   FSR
        MOVLW   40H
        MOVWF   CON
WT3     CLRF    INDF
        INCF    FSR,1
        DECFSZ  CON,1
        GOTO    WT3
WTX     RETURN
FSA     MOVLW   3FH
        MOVWF   FSR
FSA1    INCF    FSR,1
        MOVF    FSR,0
        MOVWF   INDF
        SUBLW   7FH
        SKPZ
        GOTO    FSA1
        MOVLW   9FH
        MOVWF   FSR
FSA2    INCF    FSR,1
        MOVF    FSR,0
        MOVWF   INDF
        SUBLW   0FFH
        SKPZ
        GOTO    FSA2
        RETURN
ALL1    MOVLW   3FH
        MOVWF   FSR
ALL11   INCF    FSR,1
        MOVLW   1
        MOVWF   INDF
        MOVLW   7FH
        SUBWF   FSR,0
        SKPZ
        GOTO    ALL11
        MOVLW   9FH
        MOVWF   FSR
ALL12   INCF    FSR,1
        MOVLW   2
        MOVWF   INDF
        MOVLW   0FFH
        SUBWF   FSR,0
        SKPZ
        GOTO    ALL12
        RETURN
RTT     BTFSC   FLAG,ZJ
        GOTO    RT
        BTFSS   FLAG,STR
        GOTO    RT
        BCF     FLAG,IN
        CALL    FCUT
        DECF    FSR,1
        DECF    FSR,1
        MOVF    INDF,0
        SUBWF   CON2,0
        SKPZ
        GOTO    RT
        MOVLW   0B8H
        MOVWF   FSR
        INCF    INDF,1
        MOVLW   0AH
        SUBWF   INDF,0
        SKPC
        GOTO    RT
        CLRF    INDF
        MOVLW   FLAG1
        MOVWF   FSR
        BTFSS   RC,START
        GOTO    RT1
        BTFSS   RC,STOP
        GOTO    RT2
        BTFSS   INDF,DEX
        GOTO    RT
        GOTO    RT3
RT1     BSF     INDF,DEX
        CALL    DAD
        GOTO    RT
RT2     BSF     INDF,DEX
        CALL    DAS
        GOTO    RT
RT3     CALL    ADY
        MOVLW   20H
        ADDWF   ADRES,0
        SKPNC
        MOVLW   0FFH
        BSF     STATUS,RP0
        MOVWF   GL2
        BCF     STATUS,RP0
        BSF     FLAG,IN
        MOVF    DAM1,0
        MOVWF   CON1
        MOVF    DAM2,0
        MOVWF   CON2
        CALL    FCUT
        DECF    FSR,1
        DECF    FSR,1
        MOVF    DAM2,0
        MOVWF   INDF
        DECF    FSR,1
        MOVF    DAM1,0
        MOVWF   INDF
        CLRF    DAS0
        CLRF    DAS1
RT      RETURN
CL      MOVLW   40H
        MOVWF   FSR
CL1     MOVLW   0FH
        ANDWF   INDF,0
        SUBLW   9
        SKPC
        GOTO    CL2
        MOVLW   0F0H
        ANDWF   INDF,0
        SUBLW   50H
        SKPC
CL2     CLRF    INDF
        INCF    FSR,1
        MOVLW   0FH
        ANDWF   INDF,0
        SUBLW   9
        SKPC
        GOTO    CL3
        MOVLW   0F0H
        ANDWF   INDF,0
        SUBLW   090H
        SKPC
CL3     CLRF    INDF
        INCF    FSR,1
        MOVLW   7DH
        SUBWF   FSR,0
        SKPC
        GOTO    CL1
        MOVLW   0C0H
        MOVWF   FSR
CL4     MOVLW   0FFH
        SUBWF   INDF,0
        SKPNC
        CLRF    INDF
        INCF    FSR,1
        MOVLW   0FDH
        SUBWF   FSR,0
        SKPC
        GOTO    CL4
        RETURN
J       MOVLW   FSTM
        MOVWF   FSR
        BTFSS   FLAG,ZJ
        GOTO    JB
        BTFSC   RA,CUTI
        GOTO    JH
        BTFSS   FLAG,STR
        GOTO    JH
        MOVLW   10H
        SUBWF   INDF,0
        SKPC
        GOTO    JH
        BSF     RC,J1
        GOTO    JX
JH      BCF     RC,J1
        GOTO    JX
JB      BTFSS   FLAG,STR
        GOTO    JA
        CALL    CKML
        SKPNZ
        GOTO    JA
        MOVLW   10H
        SUBWF   INDF,0
        SKPC
        GOTO    JA
        BSF     RC,J1
        CALL    JC1
        GOTO    JG
JA      BCF     RC,J1
JG      MOVF    TIM,1
        SKPZ
        GOTO    JX
        MOVLW   TTM
        MOVWF   FSR
        MOVLW   10H
        SUBWF   INDF,0
        SKPNC
        GOTO    JC
        INCF    INDF,1
        BTFSC   FLAG,OVER
        GOTO    JD
        BTFSC   FLAG,TD
        GOTO    JE
        BTFSC   FLAG,GLF
        GOTO    JE
JF      CLRF    INDF
JC      BTFSS   FLAG,GLF     
        GOTO    JC1
        BCF     FLAG,GLF
        CLRF    INDF
JC1     BCF     RC,ALM
        BCF     RC,J2
        GOTO    JX
JD      BSF     RC,J2
        MOVLW   5
        SUBWF   INDF,0
        BCF     RC,ALM
        SKPC
        BSF     RC,ALM
        MOVLW   0AH
        SUBWF   INDF,0
        SKPC
        GOTO    JX
        BCF     FLAG,OVER
        GOTO    JF
JE      BCF     RC,ALM
        BTFSC   INDF,0
        BSF     RC,ALM
JX      RETURN
FS      MOVLW   FSTM
        MOVWF   FSR
        BTFSS   FLAG,STR
        GOTO    FSN
        MOVLW   0C8H
        SUBWF   INDF,0
        SKPNC
        GOTO    FSN1
        INCF    INDF,1
        BSF     RA,3
        GOTO    FSX
FSN     CLRF    INDF
FSN1    BCF     RA,3
FSX     RETURN
SU      MOVWF   FSR
        MOVLW   73H
        SUBWF   INDF,0
        SKPZ
        GOTO    SUX
        DECF    FSR,1
        MOVLW   16H
        SUBWF   INDF,0
SUX     RETURN
LD      MOVF    CONE,0
        MOVWF   FSR
        INCF    CONE,1
        MOVF    INDF,0
        MOVWF   CLO
        MOVF    CONF,0
        MOVWF   FSR
        INCF    CONF,1
        MOVF    CLO,0
        MOVWF   INDF
        DECFSZ  CON,1
        GOTO    LD
        RETURN
LDA     MOVLW   07BH
        CALL    SU
        SKPZ
        GOTO    LDAX
        MOVLW   7AH
        MOVWF   CONE
        MOVLW   0BAH
        MOVWF   CONF
        MOVLW   4
        MOVWF   CON
        CALL    LD
        CLRF    7AH
        CLRF    7BH
        CLRF    7CH
        CLRF    7DH
LDAX    RETURN
DD1     MOVLW   0BDH
        CALL    SU
        SKPNZ
        GOTO    DD1X
        MOVLW   0BEH
        MOVWF   FSR
        INCF    INDF,1
        MOVLW   0FAH
        SUBWF   INDF,0
        SKPC
        GOTO    DD3
        CLRF    INDF
        INCF    FSR,1
        INCF    INDF,1
        MOVF    INDF,0
        MOVWF   CONE
        CALL    ADD1
        MOVF    CONE,0
        MOVWF   INDF
        GOTO    DD4
DD3     MOVLW   0BEH
        MOVWF   FSR
        MOVLW   7
        ANDWF   INDF,0
        SKPZ
        GOTO    DD1X
DD4     MOVLW   0B9H
        MOVWF   FSR
        MOVLW   4FH
        MOVWF   CONF
        MOVLW   7
        MOVWF   CON
DD2     CALL    WR
        INCF    FSR,1
        INCF    CONF,1
        DECFSZ  CON,1
        GOTO    DD2
DD1X    RETURN
        END




















































































































































        

